package cn.i7baozh.order.controller;

import cn.i7baozh.api.entities.CommonResult;
import cn.i7baozh.api.entities.Payment;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @author : baoqi.zhang
 * @date :   2022/4/6 13:50
 */
@RestController
@Slf4j
public class OrderController {

    @Autowired
    private RestTemplate restTemplate;

    private static final String payment_url = "http://localhost:8001";

    @GetMapping("/consumer/payment/create")
    public CommonResult create(Payment payment) {
        log.info("create:{}", payment);
        return restTemplate.postForObject(payment_url + "/payment/create", payment, CommonResult.class);
    }

    @GetMapping("/consumer/payment/get/{id}")
    public CommonResult getById(@PathVariable("id") Long id ) {
        String url = payment_url + "/payment/get/" + id;
        log.info("url:{}",url);
        return restTemplate.getForObject(url, CommonResult.class);
    }
}
